﻿using System;
using System.Collections.Generic;

namespace CSFP.Test
{
    public static class Util
    {
        public static bool CmpEnums<T>(System.Collections.IEnumerable coll1, System.Collections.IEnumerable coll2)
            where T : IEquatable<T>
        {
            var enum1 = coll1.GetEnumerator();
            var enum2 = coll2.GetEnumerator();
            while (enum1.MoveNext()) {
                if (!enum2.MoveNext())
                    return false;
                if (!((T)enum1.Current).Equals(((T)enum2.Current)))
                    return false;
            }
            if (enum2.MoveNext())
                return false;
            return true;
        }

        public static T[] EvalSeq<T, S>(ISeq<T, S> seq)
            where S : struct, ISeq<T, S>
        {
            var result = new List<T>();
            while (seq.IsValid) {
                result.Add(seq.First);
                seq = seq.Next;
            }
            return result.ToArray();
        }
    }
}
